﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DrivingCRM.Controller;
using System.Web.Security;
using DrivingCRM.Model;

namespace DrivingCRM.Views
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.L_LoginForm.LoggedIn +=new EventHandler(L_LoginForm_LoggedIn);
        }

        /// <summary>
        /// Méthode déclenchée lorsque l'utilisateur a été authentifié
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void L_LoginForm_LoggedIn(object sender, EventArgs e)
        {
            /// récupération du user
            List<string> type = EntityManager.GetCurrentUserType(this.L_LoginForm.UserName);

            if (type.Capacity == 2 || type.Capacity == 3)
            {
                if (type[0].Count() <= 13)
                    Session["User"] = type;
                else
                    Session["User"] = null;

                Response.Redirect("~/Views/Default.aspx");
            }
            else
                Response.Redirect("~/Views/Login.aspx");
            
            //EFMembershipUser usr = ((EFMembershipProvider)Membership.Provider).GetCurrentUser(HttpContext.Current.User.Identity.Name,true);
        }
    }
}